package com.qixiao.lib.generic.defgeneric.method;

/**
 * 泛型类声明的泛型参数不影响泛型方法申明的泛型参数，不管是否一致
 */
public class GenericMethod2 {
    static class Fruit {
        @Override
        public String toString() {
            return "furit";
        }
    }

    static class Apple extends Fruit {
        @Override
        public String toString() {
            return "Apple";
        }
    }

    static class Person {
        @Override
        public String toString() {
            return "Person";
        }
    }

    static class GenericMethod2Test<T> {
        public void show1(T t) {
            System.out.println(t.toString());
        }

        public <T> void show2(T t) {
            System.out.println(t.toString());
        }

        public <E> void show3(E t) {
            System.out.println(t.toString());
        }
    }

    public static void main(String[] args) {
        Apple apple = new Apple();
        Person person = new Person();

        GenericMethod2Test<Fruit> test = new GenericMethod2Test<>();
        GenericMethod2Test<Person> test1 = new GenericMethod2Test<>();

        Class t = test.getClass();
        Class t1 = test1.getClass();

        System.out.println(t);
        System.out.println(t1);

        test.show1(apple);
        //test.show1(person);//报错

        test.show2(apple);
        test.show2(person);

        test.show3(apple);
        test.show3(person);
    }
}
